package lbim.client.ui;

import java.util.Hashtable;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;

import de.enough.polish.ui.Form;
import de.enough.polish.ui.TextField;
import de.enough.polish.util.Locale;

/**
 *
 * @author tharindu
 */
public class Settings extends Form implements javax.microedition.lcdui.CommandListener {

    private MainUI ui_;
    private Hashtable commands_;
    private boolean valid;

    //#style textfieldItem
    final private TextField server_ = new TextField(Locale.get("settings.server"), "http://127.0.0.1:8080", 100, TextField.ANY);//[LOCALE]

    public Settings() {

        //#style mainScreen
        super(Locale.get("settings.title")); //[LOCALE]

        ui_ = MainUI.getInstance();
        commands_ = ui_.getCommands();

        try {
            setCommandListener(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        addCommand((Command) commands_.get(new Integer(MainUI.CMD_SAVE)));
        addCommand((Command) commands_.get(new Integer(MainUI.CMD_CANCEL)));

        this.append(server_);

    }

    public boolean isValidChange() {
        valid = false;
        if (server_.getText().length() != 0) {
            valid = true;
        }
        return valid;
    }

    public String getServerUrl() {
        return server_.getText();
    }

    public void commandAction(Command c, Displayable d) {
        MainUI.hsenidCommand(c, d);
    }
}
